<?php
/**
 * Created by PhpStorm.
 * User: 丶晓
 * Date: 2017/8/11
 * Time: 10:12
 */

namespace app\api\model;


use think\Db;
use think\Model;

class BindModel extends Model
{
    public function seleteInfo($type, $data)
    {
        switch ($type) {
            case 'isBindMiniAppId':
                if (!isset($data['miniID']) or !isset($data['openID']) or !Db::table('wyz_miniapps')->where('id', $data['miniID'])->count()) {
                    return false;
                }
                if (Db::table('wyz_miniapps')->where('id', $data['miniID'])
                    ->where('callback_wechat_id=', 'eq', $data['openID'])->count()) {
                    return true;
                }
                return false;
                break;
            case 'appName':
                if (!isset($data['miniID']) or !Db::table('wyz_miniapps')->where('id', $data['miniID'])->count()) {
                    return false;
                }
                return Db::table('wyz_miniapps')->where('id', $data['miniID'])->value('name');
                break;
        }
        return false;
    }

    public function changeInfo($type, $data)
    {
        switch ($type) {
            case 'BindMiniAppId':
                if (!isset($data['miniID']) or !isset($data['openID']) or !Db::table('wyz_miniapps')->where('id', $data['miniID'])->count()) {
                    return false;
                }
                Db::table('wyz_miniapps')->where('id', $data['miniID'])->update(['callback_wechat_id' => $data['openID']]);
                return true;
                break;
        }
        return false;
    }
}